<?php include("../config.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title><?php echo $sitename; ?> - Sysop: Processing Submission</title>
<meta name="description" content="<?php echo $sitename; ?> - Sysop: Processing Submission">
<meta name="keywords" content="free to try, software, shareware, freeware, developers, vendors, download, PAD">
<meta name="author" content="Andrey Aleksanyants, M.D.">
<meta name="copyright" content="easy HTools">
<meta http-equiv="imagetoolbar" content="no">
<link rel="stylesheet" type="text/css" href="../<?php echo $cssfile; ?>">
<link rel="shortcut icon" href="../favicon.ico">
</head>
<body>
<table class="tmain" align="center" width="90%" cellspacing="0" cellpadding="0">
<tr>
<td class="tmain">
<table class="tlogo" align="center" width="100%" cellspacing="0" cellpadding="4">
<tr>
<td align="right">
<p><a href="index.php">Home</a></p>
</td>
</tr>
</table>
</td>
</tr><tr>
<td class="tmain">
<br>
<table align="center" width="100%" border="0" cellspacing="0" cellpadding="1">
<tr valign="top">
<td class="tbody">
<h1><?php echo $sitename; ?> - Sysop: Processing Submission</h1>
<?php

// Requesting URL data
$submid = $_GET["submid"];
$action = $_GET["action"];
if(empty($submid) or !intval($submid) or (($action != "accept") && ($action != "decline"))) {
	die("<p><b>Invalid page access!</b></p>\n");
}
// Connecting to database
if(!($link_id = mysql_connect($dbhost, $userid, $userpassword))) {
	die("<p><b>Error connecting to the database server:</b> " . mysql_error() . "</p>\n");
}
mysql_select_db($dbname);

// Receiving the required information from paddata
$result = mysql_query("SELECT * FROM submitlog WHERE submid='$submid'", $link_id);
$query = mysql_fetch_array($result);
mysql_free_result($result);
if(empty($query)) { // If there was no such entry in database
	header("HTTP/1.0 404 Not Found"); // Redirecting to the main page
	die("<p><b>No such entry in database!</b></p>\n");
}
$company      = addslashes($query["company"]);
$country      = addslashes($query["country"]);
$website      = addslashes($query["website"]);
$contactname  = addslashes($query["contactname"]);
$email        = addslashes($query["email"]);
$title        = addslashes($query["title"]);
$version      = addslashes($query["version"]);
$pdate        = addslashes($query["pdate"]);
$cost         = addslashes($query["cost"]);
$ptype        = addslashes($query["ptype"]);
$install      = addslashes($query["install"]);
$os           = addslashes($query["os"]);
$languages    = addslashes($query["languages"]);
$changeinfo   = addslashes($query["changeinfo"]);
$category     = addslashes($query["category"]);
$requirements = addslashes($query["requirements"]);
$ksize        = addslashes($query["ksize"]);
$keywords     = addslashes($query["keywords"]);
$description  = addslashes($query["description"]);
$descrlarge   = addslashes($query["descrlarge"]);
$homepage     = addslashes($query["homepage"]);
$screenshot   = addslashes($query["screenshot"]);
$icon         = addslashes($query["icon"]);
$padfile      = addslashes($query["padfile"]);
$download     = addslashes($query["download"]);
$aspnumber    = addslashes($query["aspnumber"]);
$affiliate    = addslashes($query["affiliate"]);
$affiliateid  = addslashes($query["affiliateid"]);
$poll         = 0;

if($action == "accept") {

	// Checking if company/title or PAD URL already in paddata table
	$result = mysql_query("SELECT * FROM paddata WHERE padfile = '$padfile'", $link_id);
	$query = mysql_fetch_array($result);
	if(empty($query)) { // If there was no such entry in database
		// Adding new software to paddata table
		$sql = "INSERT INTO paddata (company, country, website, contactname, email, title, version, pdate, cost, ptype, install, os, languages, changeinfo, category, requirements, ksize, keywords, description, descrlarge, homepage, screenshot, icon, padfile, download, aspnumber, affiliate, affiliateid, poll) VALUES ('$company', '$country', '$website', '$contactname', '$email', '$title', '$version', '$pdate', '$cost', '$ptype', '$install', '$os', '$languages', '$changeinfo', '$category', '$requirements', '$ksize', '$keywords', '$description', '$descrlarge', '$homepage', '$screenshot', '$icon', '$padfile', '$download', '$aspnumber', '$affiliate', '$affiliateid', '$poll')";
		mysql_query($sql, $link_id) or die("<p><b>Error inserting paddata table:</b> " . mysql_error() . "</p>\n<p>" . $sql . "</p>\n");
		$progid = sprintf("%d", mysql_insert_id($link_id));
		echo "<p>New program successfully added. View details <a target=\"_blank\" href=\"/details.php?progid=" . $progid . "\">here</a>.</p><br>\n";
	
		// Sending notification mail about adding new program
		$subject  = $title . " has been published on " . $sitename;
		$message  = "Dear " . $contactname . "!\r\n\r\n";
		$message .= "Your software, \"" . $title . " " . $version . "\", has been reviewed by our staff and has been published on " . $sitename . " and all related sites.\r\n\r\n";
		$message .= "Affiliate Data:\r\n";
		if($affiliate && $affiliateid) $message.= $affiliate . ", Product ID: ". $affiliateid . "\r\n\r\n";
		else                $message .= "Not established\r\n\r\n";
		$message .= "You can view your software listing here: http://" . $_SERVER['HTTP_HOST'] . "/details.php?progid=" . $progid . "\r\n\r\n";
		$message .= "If your software has been rated at " . $sitename . ", you can get the award logo from http://" . $_SERVER['HTTP_HOST'] . "/awards.php and link it to your software description page.\r\n";
		$message .= "If your software has not been rated yet, you can apply for " . $sitename . " award from http://" . $_SERVER['HTTP_HOST'] . "/applyaward.php\r\n\r\n";
		$message .= "If you have any questions or comments please do not hesitate to contact us at " . $sitemail . " or by filling contact form here: http://" . $_SERVER['HTTP_HOST'] . "/contact.php\r\n\r\n";
		$message .= "Kind regards,\r\n\r\n";
		$message .= $sitename . " webmaster\r\n";
		$headers  = "From: \"" . $sitemail . "\"<" . $sitemail . ">\r\n";
		$headers .= "Reply-To: \"" . $sitemail . "\"<" . $sitemail . ">\r\n";
		$headers .= "Content-Type: text/plain; charset=windows-1252";
		@mail($email, $subject, $message, $headers);
	}
	else {
		$progid        = $query["progid"];
		$dbaffiliate   = $query["affiliate"];
		$dbaffiliateid = $query["affiliateid"];
		if(!$affiliate || !$affiliateid) { // if no new data, keep old data
			$affiliate   = $dbaffiliate;
			$affiliateid = $dbaffiliateid;
		}
		// Updating the existing software in paddata table
		$sql = "UPDATE paddata SET company = '$company', country = '$country', website = '$website', contactname = '$contactname', email = '$email', title = '$title', version = '$version', pdate = '$pdate', cost = '$cost', ptype = '$ptype', status = '1', install = '$install', os = '$os', languages = '$languages', changeinfo = '$changeinfo', category = '$category', requirements = '$requirements', ksize = '$ksize', keywords = '$keywords', description = '$description', descrlarge = '$descrlarge ', homepage = '$homepage', screenshot = '$screenshot', icon = '$icon', padfile = '$padfile', download = '$download', aspnumber = '$aspnumber', affiliate = '$affiliate', affiliateid = '$affiliateid', poll = '$poll' WHERE progid = '$progid'";
		mysql_query($sql, $link_id) or die("<p><b>Error updating paddata table:</b> " . mysql_error() . "</p>\n<p>" . $sql . "</p>\n");

		echo "<p>Existing program record successfully updated. View details <a target=\"_blank\" href=\"/details.php?progid=" . $progid . "\">here</a>.</p><br>\n";
		
		// Sending notification mail about updating of existing program
		$subject  = $title . " has been updated on " . $sitename;
		$message  = "Dear " . $contactname . "\r\n\r\n";
		$message .= "Your software, \"" . $title . " " . $version . "\", has been updated on " . $sitename . ".\r\n\r\n";
		$message .= "Affiliate Data:\r\n";
		if($affiliate && $affiliateid) $message.= $affiliate . ", Product ID: ". $affiliateid . "\r\n\r\n";
		else                $message .= "Not established\r\n\r\n";
		$message .= "You can view your software listing here: http://" . $_SERVER['HTTP_HOST'] . "/details.php?progid=" . $progid . "\r\n\r\n";
		$message .= "If your software has been rated at " . $sitename . ", you can get the award logo from http://" . $_SERVER['HTTP_HOST'] . "/awards.php and link it to your software description page.\r\n";
		$message .= "If your software has not been rated yet, you can apply for " . $sitename . " award from http://" . $_SERVER['HTTP_HOST'] . "/applyaward.php\r\n\r\n";
		$message .= "If you have any questions or comments please do not hesitate to contact us at " . $sitemail . " or by filling contact form here: http://" . $_SERVER['HTTP_HOST'] . "/contact.php\r\n\r\n";
		$message .= "Kind regards,\r\n\r\n";
		$message .= $sitename . " webmaster\r\n";
		$headers  = "From: \"" . $sitemail . "\"<" . $sitemail . ">\r\n";
		$headers .= "Reply-To: \"" . $sitemail . "\"<" . $sitemail . ">\r\n";
		$headers .= "Content-Type: text/plain; charset=windows-1252";
		@mail($email, $subject, $message, $headers);
	}
}

if($action == "decline") {
	// Sending notification mail about adding new program
	$subject  = $title . " was NOT added to " . $sitename;
	$message  = "Dear " . $contactname . "!\r\n\r\n";
	$message .= "Your software, \"" . $title . " " . $version . "\", has been reviewed by our staff and was NOT added to " . $sitename . " database.\r\n\r\n";
	$message .= "If you have any questions or comments please do not hesitate to contact us at " . $sitemail . " or by filling contact form here: http://" . $_SERVER['HTTP_HOST'] . "/contact.php\r\n\r\n";
	$message .= "Kind regards,\r\n\r\n";
	$message .= $sitename . " webmaster\r\n";
	$headers  = "From: \"" . $sitemail . "\"<" . $sitemail . ">\r\n";
	$headers .= "Reply-To: \"" . $sitemail . "\"<" . $sitemail . ">\r\n";
	$headers .= "Content-Type: text/plain; charset=windows-1252";
	@mail($email, $subject, $message, $headers);
}
mysql_query("DELETE FROM submitlog WHERE submid = '$submid'", $link_id) or die("<p><b>Error deleting record from submitlog table:</b> " . mysql_error() . "</p>\n");
echo "<p>" . $padfile . " has been successfully deleted from submitlog table.</p><br>\n";
echo "<p><a href=\"submmanage.php\">Manage</a> your Submissions.</p>\n";

// Disconnect from database
mysql_close($link_id);
?>
<br>

</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
